package cn.xopencode.appletweb.controller.security.activity;

import cn.hutool.core.util.IdUtil;
import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.score.api.rpc.ScoreRpc;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import cn.xopencode.securityservice.rpc.activity.ActivityRpc;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityCreateReqDTO;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityPageReqDTO;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.checkerframework.checker.units.qual.A;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static cn.xopencode.common.framework.vo.CommonResult.success;

@Api(tags = "安全活动与技能比武情况 API")
@RestController
@RequestMapping("/activity")
@Validated
public class SecurityActivityController {

    @DubboReference(version = "${dubbo.consumer.ActivityRpc.version}")
    private ActivityRpc activityRpc;

    @ApiOperation(value = "根据ID获得安全活动与技能比武情况")
    @GetMapping("/get/{activityId}")
    public CommonResult<ActivityRespDTO> getActivity(@PathVariable(value="activityId",required=false)String activityId) {
        /*return activityRpc.getActivity(activityId);*/
        ActivityRespDTO actRespDTO= new ActivityRespDTO();
        actRespDTO.setId(IdUtil.objectId());
        actRespDTO.setActivityTime(new Date());
        actRespDTO.setActivityType(1);
        actRespDTO.setContent("aaaa");
        actRespDTO.setRanking(2);
        actRespDTO.setParticipatingRole(1);
        actRespDTO.setRemark("ssss");
        return success(actRespDTO);
    }

    /**
     * 分页获取安全活动与技能比武情况
     * @param pageDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页获取安全活动与技能比武情况")
    public CommonResult<PageResult<ActivityRespDTO>> pageActivity(ActivityPageReqDTO pageDTO){
        /*return activityRpc.pageActivity(pageDTO);*/
        ActivityRespDTO actRespDTO= new ActivityRespDTO();
        actRespDTO.setId(IdUtil.objectId());
        actRespDTO.setActivityTime(new Date());
        actRespDTO.setActivityType(1);
        actRespDTO.setContent("bbbbb");
        actRespDTO.setRanking(2);
        actRespDTO.setParticipatingRole(1);
        actRespDTO.setRemark("ssss");

        ActivityRespDTO actRespDTO1= new ActivityRespDTO();
        actRespDTO1.setId(IdUtil.objectId());
        actRespDTO1.setActivityTime(new Date());
        actRespDTO1.setActivityType(2);
        actRespDTO1.setContent("aaaa");
        actRespDTO1.setRanking(1);
        actRespDTO1.setParticipatingRole(2);
        actRespDTO1.setRemark("ffff");

        List<ActivityRespDTO> alist = new ArrayList<ActivityRespDTO>();
        alist.add(actRespDTO);
        alist.add(actRespDTO1);

        PageResult<ActivityRespDTO> page = new PageResult<ActivityRespDTO>();
        page.setList(alist);

        return success(page);
    }

    /**
     *  新增安全活动与技能比武情况
     * @param createDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增安全活动与技能比武情况")
    public CommonResult<Integer> createActivity(@Valid ActivityCreateReqDTO createDTO){
        return success(1);
    }
}
